<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!--   获取绝对路径 -->
<c:set var="ctx" value="${pageContext.request.contextPath }" />
<%@ include file="/common/include/include.jsp"%>
<style>
	.lay-body{
		margin-top: 52px;
		overflow-y: auto;
		overflow-x: unset;
	}
	.lay-header{
		position: absolute;
		top: 0px;
		width: 100%;
	}
</style>
<div class="modal-dialog" style="width:100%">
    <div class="modal-content">
        <div class="modal-header lay-header">
            <button type="button" class="close" data-dismiss="modal" onclick="{parent.layer.closeAll();}"><i class="pci-cross pci-circle"></i></button>
            <h4 class="modal-title">选择父级菜单</h4>
        </div>

        <div class="modal-body lay-body">
            <ul id="treeDemo" class="ztree"></ul>
        </div>
    </div>
</div>

<script>
//树
$(document).ready(function() {
	//初始化树
	var clientH = document.body.clientHeight-54;
	$(".lay-body").css("height",clientH+"px");
	onloadZTree();//加载树形图
});
//设置树形图的各个属性
var setting = {
	//是否异步
	async : {
		enable:true,
	},
	//树形显示节点，不设置这个属性，便不会区分父节点和子节点
	data: {
		simpleData: {
			enable: true
		}
	},
	//回调函数，这里设置了节点单击事件,noClick属性的值要与自定义的处理单击事件的函数值一致
	callback : {
		onClick : clickNode
	}
};

//加载ztree  
function onloadZTree() {
	var ztreeNodes;
	$.ajax({
		async : true, //是否异步  
		cache : false, //是否使用缓存  
		type : 'post', //请求方式,post  
		dataType : "json", //数据传输格式  
		url : "${ctx }/admin/menu/getMenuTree", //请求链接  
		error : function() {
			alert('亲，网络有点不给力呀！');
		},
		success : function(data) {
			ztreeNodes = eval("[" + data + "]"); //将string类型转换成json对象
			$.fn.zTree.init($("#treeDemo"), setting, ztreeNodes);
			//获取这个数的对象，treeDemo与这棵树的id相对应
			var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
			//表示 展开 全部节点
			treeObj.expandAll(true);
		}
	});
};

/***
* 选择树
**/
function clickNode(event, treeId, treeNode, clickFlag) {
	parent.setOneMenuNode(treeNode);	
}

</script>
